#include "coreutils.h"

#define FOLDER_BLUE "\x1B[34m"
#define UNKNOWN_WHITE "\x1B[0m"
#define EXECUTABLE_GREEN "\x1B[32m"

int main(int ac, char** av)
{
    DIR* d;
    if (ac != 2)
        d = opendir(".");
    else 
        d = opendir(av[1]);
    
    struct dirent* dir;

    while ((dir = readdir(d)) != NULL) {
        if (strcmp(dir->d_name, ".") != 0 && strcmp(dir->d_name, "..") != 0) {
            if (dir->d_type == DT_DIR)
                fprintf(stdout, "%s%s  ", FOLDER_BLUE, dir->d_name);
            else if (dir->d_type != DT_DIR)
                fprintf(stdout, "%s%s  ", EXECUTABLE_GREEN, dir->d_name);
            else 
                fprintf(stdout, "%s%s  ", UNKNOWN_WHITE, dir->d_name);
        }
    }

    fprintf(stdout, "\n");

    closedir(d);

    free(d);
    free(dir);

    return 0;
}

